// pages/cation/cation.js
const app = getApp()
Page({
  data: {
    navindex: 0,
    nav: [
      { txt: '移动宽带' },
      { txt: '联通宽带' },
      { txt: '电信宽带' },
      { txt: '其他业务' },
      
    ],
    yidong: [
      {
        urls: "../../images/banner1.jpg",
        name: "需使用4G飞享套餐。赠送12GB流量，2400分钟通话",
        price: "1370",
        shuliang: "1",
        pid: '123',
      },
      {
        urls: "../../images/banner1.jpg",
        name: "需使用4G飞享套餐。赠送12GB流量，2400分钟通话",
        price: "1370",
        shuliang: "1",
        pid: '12',
      }, {
        urls: "../../images/banner1.jpg",
        name: "需使用4G飞享套餐。赠送12GB流量，2400分钟通话",
        price: "1370",
        shuliang: "1",
        pid: '1234',
      }, {
        urls: "../../images/banner1.jpg",
        name: "需使用4G飞享套餐。赠送12GB流量，2400分钟通话",
        price: "1370",
        shuliang: "1",
        pid: '1235',
      },     
    ],
    // text:"这是一个页面"
    tip: '',
    buttonDisabled: false,
    modalHidden: true,
    show: false
  },
  //购买
  buy: function (e) {
    var id = e.currentTarget.dataset.id;
    app.navTo('../buy/buy?id='+id)
  },
  click: function (e) {
    var that=this;
    var id = e.currentTarget.dataset.id;
   
    this.setData({
      navindex: id
    })
    wx.request({
      url: app.appUrl + '/goods/menulist',
      data: {
        bid: 18,
        menu: id
      },
      success: function (res) {
        
        that.setData({
          goods: res.data.data
        })
      }
    })
    // wx.request({
    //   url: 'https://yunying.135k.com/api/goods/myposs',
    //   data: {
    //   },
    //   success: function (res) {
    //     that.setData({
    //       list: res.data.data
    //     })
    //   }
    // })
  },
  onLoad: function (e) {
 
  },
  onShow: function () {
    var that = this;
    var navindex = that.data.navindex; //重新定义navindex    
    var state = wx.getStorageSync('state')

    if (state == "success") {    //判断是否从首页进入该页面
      var navindex = wx.getStorageSync('fenlei')
      that.setData({
        navindex: navindex,
      })
      wx.removeStorageSync('fenlei')
    }else{
      that.setData({
        navindex: 0,
      })
    }
    
    wx.request({
      url: app.appUrl+'/goods/menulist',
      data:{
        bid:18,
        menu: that.data.navindex
      },
      success:function(res){
        that.setData({
          goods:res.data.data
        })
      }
    })
    // wx.getStorage({
    //   key: 'fenlei',
    //   success: function (res) {
    //     console.log(res.data)
    //     that.setData({
    //       navindex: res.data,
    //     })
    //   }
    // })
  },
  kdxq: function (e) {
   
    var id = e.currentTarget.dataset.id
    app.navTo('../dingdan/dingdan?id=' + id)
  },
  kdyy: function (e) {
  
    app.navTo('../yuyue/yuyue')
  },
}) 



